﻿/// <reference path="../scripts/jquery-1.11.2.min.js" />
/// <reference path="../scripts/bootstrap.min.js" />

if (typeof ($) != "undefined" && $) {
    //验证用户
    if ($.cookie('openid') == null || $.cookie('openid') == '') {
        window.location.href = 'empvalidate.html';
    }
    else {
        $(document).ready(onReady);
    }
}

function onReady() {
    $("#btnRegister").click(function () {
        var mobile = $("#mobile").val();
        if (!CheckMobile(mobile)) {
            showToast("请输入正确的手机号");
        }
        else {
            var data = { mobile: mobile, openid: $.cookie('openid') };
            $.ajax({
                type: "post",
                url: "api/login.ashx?ac=active&k=" + Math.random(),
                data: data,
                beforeSend: function () {
                    $('#loadingToast').show();
                },
                error: function () {
                    showToast("登录失败");
                },
                success: function (data) {
                    var obj = eval("(" + data + ")").result;
                    if (obj.r == "suc") {
                        showToast(obj.val);
                        window.location.href = "emplist.html";
                    }
                    else {
                        showToast(obj.val);
                    }
                },
                complete: function () {
                    $('#loadingToast').hide();
                }
            });
        }
    });
}

function CheckMobile(mobile) {
    var myreg = /^\d{11}$/;
    if (myreg.test(mobile)) {
        return true;
    }
    else {
        return false;
    }
}